package sctu.edu.java.year2016.team01.xuhanmei.day20160606.LearnThread;

/**
 * Created by Administrator on 2016/6/6.
 */
public class RunnableImpl implements Runnable {
    int i = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {//同步锁，这样其他线程就只能等待
                System.out.println(Thread.currentThread().getName() + i);//Thread.currentThread()是返回当前正在执行的线程
                i--;
                Thread.yield();//当前正在运行的线程让出cpu，所有的线程再去争cpu
                if (i < 0) {
                    break;
                }
            }
        }
    }
}

